package com.windfone.web;

import java.util.List;

import javax.servlet.ServletContext;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.tagext.TagSupport;

import org.springframework.web.context.support.WebApplicationContextUtils;

import com.windfone.model.StaticAbout;
import com.windfone.service.CommonService;

public   class StaticTag extends TagSupport {
	/**	serialVersionUID */
	private static final long serialVersionUID = 1L;
	private CommonService commonService;
	private List<StaticAbout> abouts;
	private String attriName;
	private String shortName;
	private String shortNameAttriName;
	private StaticAbout about;
	public String getShortNameAttriName() {
		return shortNameAttriName;
	}

	public void setShortNameAttriName(String shortNameAttriName) {
		this.shortNameAttriName = shortNameAttriName;
	}

	public StaticAbout getAbout() {
		return about;
	}

	public void setAbout(StaticAbout about) {
		this.about = about;
	}

	public String getShortName() {
		return shortName;
	}

	public void setShortName(String shortName) {
		this.shortName = shortName;
	}

	public List<StaticAbout> getAbouts() {
		return abouts;
	}

	public String getAttriName() {
		return attriName;
	}

	public void setAbouts(List<StaticAbout> abouts) {
		this.abouts = abouts;
	}

	public void setAttriName(String attriName) {
		this.attriName = attriName;
	}

	public int doStartTag() throws JspException {
		ServletContext sc = pageContext.getServletContext();
		if ( commonService == null )
			commonService = (CommonService) WebApplicationContextUtils.getWebApplicationContext(sc).getBean("commonService");
		if ( attriName != null ){
			abouts = commonService.getAllStaticAboutName();
			this.pageContext.setAttribute(attriName,abouts);
		}
		if ( shortName != null){
			about = commonService.getStaticAboutByShortName(shortName);
			this.pageContext.setAttribute(shortNameAttriName,about);
		}
		return(SKIP_BODY);
 
	}
}
